home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig15_12.jar / Ch15 / Fig15_12 / STACK / Driver.cpp next >
C/C++ Source or Header  |  1997-11-04  |  1KB  |  52 lines

  1. // Stack test program
  2. #include <iostream.h>
  3. #include "stack.h"
  4.  
  5. int main()
  6. {
  7.    Stack<int> intStack;
  8.  
  9.    cout << "Pushing integers on intStack" << endl;
  10.  
  11.    for ( int i = 0; i < 5; i++ ) {
  12.       intStack.push( i );       // put items in the stack
  13.       cout << i << ' ';
  14.    }
  15.  
  16.    cout << endl;
  17.  
  18.    intStack.print();          // output the stack contents
  19.  
  20.    cout << endl << "Popping integers from intStack" << endl;
  21.  
  22.    while ( !intStack.isEmpty() )
  23.       cout << intStack.pop() << ' ';   // remove items
  24.  
  25.    cout << endl;
  26.    intStack.print();          // output the stack contents
  27.  
  28.    Stack<char> charStack;
  29.  
  30.    cout << endl << endl
  31.         << "Pushing characters on charStack" << endl;
  32.  
  33.    for ( char c = 'A'; c < 'E'; c++ ) {
  34.       charStack.push( c );      // put items in the stack
  35.       cout << c << ' ';
  36.    }
  37.  
  38.    cout << endl;
  39.  
  40.    charStack.print();         // output the stack contents
  41.  
  42.    cout << endl << "Popping characters from charStack" << endl;
  43.  
  44.    while ( !charStack.isEmpty() )
  45.       cout << charStack.pop() << ' ';   // remove items
  46.  
  47.    cout << endl;
  48.    charStack.print();         // output the stack contents
  49.  
  50.    return 0;
  51. }
  52.